/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package palettecreator;

import java.awt.Color;
import java.awt.Graphics;
import java.awt.geom.AffineTransform;
import java.awt.image.AffineTransformOp;
import java.awt.image.BufferedImage;
import java.awt.image.ImageFilter;

/**
 *
 * @author anatoliy.sviridenko
 */
public class ImageView extends javax.swing.JPanel implements Runnable
{
    BufferedImage image;
    BufferedImage origImage;

    public double scale = 1.0;

    Color bgColor;

    public ImageView()
    {
	super();
        new Thread(this).start();
    }

    public void run()
    {
	while(true)
        {
            repaint();
            try
            {
                Thread.sleep(30);
            }
            catch(Exception e)
            {
                e.printStackTrace();
            }
        }
    }

//    public Color getColor(int x, int y)
//    {
//
//    }

    @Override
    public void paintComponent(Graphics g)
    {
	g.setColor(bgColor);
	g.fillRect(0, 0, (int) g.getClipBounds().getWidth(), (int) g.getClipBounds().getHeight());
	if (image != null)
	{
	    AffineTransform scaleTransform = new AffineTransform();
	    scaleTransform.scale(scale, scale);
	    AffineTransformOp filter = new AffineTransformOp(scaleTransform, AffineTransformOp.TYPE_NEAREST_NEIGHBOR);
	    BufferedImage tmpImage = filter.filter(image, null);

	    g.drawImage(tmpImage, 0, 0, null);
	}
    }
}
